﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class ES_TrainingRequest : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        ITrainingScholarshipTypeBLL SchTypeBLL = new TrainingScholarshipTypeBLL();
        ITrainingScholarshipFundBLL SchFundBLL = new TrainingScholarshipFundBLL();
        TrainingCoursesDAL courseDAL = new TrainingCoursesDAL();
        TrainingCoursesDesDtlsBLL CDesBLL = new TrainingCoursesDesDtlsBLL();
        IEmployeeBLL EmpBLL = new EmployeeBLL();
        ConvertNullable cn = new ConvertNullable();


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDataGrid();
                LoadTrainingCours();
            }
        }

        private void LoadDataGrid()
        {

            DataSet ListDataCommand = CDesBLL.GetData(ssMng.EmpSeq, "", "");
            DataTable table = ListDataCommand.Tables[0];
            //DataSet ListDataCommand = courseDAL.GetData();
            //DataTable table = ListDataCommand.Tables[0];
            //tblTRCoursDesList.DataSource = ListSalaryCommand.Tables[0];
            //RadGrid2.DataSource = courseDAL.GetFull();
            RadGrid2.DataSource = ListDataCommand.Tables[0];
            RadGrid2.DataBind();
        }
        protected void RadGrid2_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {

            }
            if (e.CommandName == "AddData")
            {
                UpdateUI2("AddNew");
            }
            LoadDataGrid();
        }
        protected void LoadTrainingCours()
        {
            DataSet ListDataCommand = courseDAL.GetData();
            DataTable table = ListDataCommand.Tables[0];
            cbTrainingCur.DataSource = ListDataCommand.Tables[0];
            cbTrainingCur.DataBind();
        }
        protected void cbTrainingCur_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            LoadDetail();  
        }
        protected void LoadDetail()
        {
            TrainingCoursesInfo info = courseDAL.GetData(Convert.ToInt32(cbTrainingCur.SelectedValue));
            //lbTrainingCourseDescr.Text = info.training_course_descr;
            //lbTotalScore.Text = info.total_score.ToString();
            lbTotalPrice.Text = info.total_price.ToString();
            if (info.date_sign_start.ToString().Length > 0)
            { lbDateSignStard.Text = info.date_sign_start.Value.ToShortDateString(); }
            if (info.date_sign_end.ToString().Length > 0)
            { lbDateSignEnd.Text = info.date_sign_end.Value.ToShortDateString(); }
            if (info.date_training_start.ToString().Length > 0)
            { lbDateTrainStard.Text = info.date_training_start.Value.ToShortDateString(); }
            if (info.date_training_end.ToString().Length > 0)
            { lbDateTrainEnd.Text = info.date_training_end.Value.ToShortDateString(); }
            lbTotalPrice.Text = info.total_price.ToString();
            //lbTotalScore.Text = info.total_score.ToString();
            lbMaxTrainee.Text = info.max_trainee_count.ToString();
            lbSchedule.Text = info.schedule_text.ToString();
            string TrainSeq = cbTrainingCur.SelectedValue;
            DataSet ListDataCommand = CDesBLL.GetData("", TrainSeq, "");
            if (ListDataCommand.Tables.Count > 0)
            {
                DataTable table = ListDataCommand.Tables[0];
                if (table.Rows.Count > 0)
                { lbQuota.Text = table.Rows[0]["COUNT_QUTA"].ToString(); }
            }
        }
        protected void btnSave2_Click(object sender, EventArgs e)
        {
            //string strJobSite = cbJobSite.SelectedValue;//CDesBLL.GetData(cbEmployeeList.SelectedValue);
                //string strJobSite = ListJobSite.Tables[0];
                string TrainSeq = cbTrainingCur.SelectedValue;
                string User = ssMng.EmpSeq;
                string JobSiteSeq = "";
                string WorkingName = "";
                string ClassName = "";
                string PostName = "";
                DataSet ListSalaryCommand = EmpBLL.LoadEmployees(cn.ConvertNullInt(User), "1", true, "");
                if (ListSalaryCommand.Tables.Count > 0)
                {
                    DataTable table = ListSalaryCommand.Tables[0];
                    JobSiteSeq = table.Rows[0]["JOB_SITE_SEQ"].ToString();
                    WorkingName = table.Rows[0]["WORKING_JOB_SITE_NAME"].ToString();
                    ClassName = table.Rows[0]["CLASS_NAME"].ToString();
                    PostName = table.Rows[0]["POS_NAME"].ToString();
                }



                CDesBLL.InsertByTrainee(TrainSeq, User, "", JobSiteSeq, WorkingName, PostName, ClassName, User);
                LoadDataGrid();
        }
        protected void btnCancel2_Click(object sender, EventArgs e)
        {
            UpdateUI2("Cancel");
        }
        protected void UpdateUI2(string strCommand)
        {
            switch (strCommand)
            {
                case "Save":
                    PanelGrid.Visible = true;
                    PanelAddData2.Visible = false;

                    break;

                case "AddNew":
                    PanelGrid.Visible = false;
                    PanelAddData2.Visible = true;
                    btnSave2.Visible = true;

                    break;

                case "Cancel":
                    PanelGrid.Visible = true;
                    PanelAddData2.Visible = false;

                    break;

                case "Update":
                    PanelGrid.Visible = false;
                    PanelAddData2.Visible = true;
                    btnSave2.Visible = false;

                    break;
            }
        }
    }
}

